﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">

    <title>用户登录</title>
    <link href="login/bootstrap.min.css" rel="stylesheet">
    <link href="login/style.min.css" rel="stylesheet">
    <link href="login/login.min.css" rel="stylesheet">

    <style>
        body {
            background: url(./login/4.jpg) repeat scroll 0 100%
        }

        .inp {
            border: 1px solid gray;
            padding: 0 10px;
            width: 200px;
            height: 30px;
            font-size: 18px;
        }

        #embed-captcha {
            width: 250px;
            margin: 0 auto;
        }

        .show {
            display: block;
        }

        .hide {
            display: none;
        }

        #notice {
            color: red;
        }

        /* 以下遮罩层为demo.用户可自行设计实现 */
        #mask {
            display: none;
            position: fixed;
            text-align: center;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            overflow: auto;
        }

        /* 可自行设计实现captcha的位置大小 */
        .popup-mobile {
            position: relative;
        }

        #popup-captcha-mobile {
            position: fixed;
            display: none;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            -webkit-transform: translate(-50%, -50%);
            z-index: 9999;
        }
    </style>

    <style type="text/css">
        html {
            overflow-y: hidden;
        }
    </style>
    <script type="text/javascript">
        var url = '/Public';
    </script>

    <link rel="stylesheet" href="login/layer.css" id="layui_layer_skinlayercss" style="">
</head>
<body style="font-size: 14px; zoom: 1;">
<div class="signinpanel">
    <div class="row">
        <div class="col-sm-7">
            <div class="signin-info" style="color:#ffffff">
                <div class="logopanel m-b">
                    <h1>登录</h1>
                </div>
                <div class="m-b"></div>
                <h3>欢迎使用后台管理系统</h3>
                <!--           <ul class="m-b">
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势一</li>
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势二</li>
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势三</li>
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势四</li>
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势五</li>
                </ul>
                <strong>还没有账号？ <a href="#" data-toggle="modal" data-target="#myModalreg">立即注册&raquo;</a></strong> -->

            </div>
        </div>

        <div class="col-sm-5" style="color:#ffffff">
            <input type="hidden" id="token" th:value="${token}">
            <input type="hidden" id="salt" th:value="${salt}">
            <form id="runlogin" name="runlogin" method="post" action="#">

                <p class="m-t-md">后台管理系统</p>
                <input type="text" class="form-control uname" id="username"
                       placeholder="用户名">
                <input type="password" class="form-control pword m-b" id="password" placeholder="密码">
                <input type="text" name="code" class="form-control pword" id="code" placeholder="验证码"
                       oncontextmenu="return false" onpaste="return false" style="width: 60%;"/>
                <img class="verifyimg reloadverify" alt="点击切换" src="verify" height="35px" ;
                     style="margin-top:-35px;width:80px;float:right;border:1px solid #cececf; "/>
                <br/>

                <p id="wait" class="hide">正在加载验证码......</p>

                <br>
                <a href="#" data-toggle="modal" data-target="#forget">忘记密码了？</a>
                <button type="button" class="btn btn-primary btn-block" onclick="login()">登&nbsp;&nbsp;&nbsp;录</button>
            </form>
        </div>
    </div>
    <div class="signup-footer">
        <div class="pull-left" style="color:#ffffff">
            后台管理系统 Copyright © 2017
        </div>
    </div>
</div>
<script src="login/jquery.min.js"></script>
<script src="login/bootstrap.min.js"></script>
<script src="login/layer.js"></script>
<script src="login/crypto.min.js"></script>
<script type="text/javascript">

    function login() {

        var checked = logcheckForm();

        if (!checked) {
            return;
        }
        var key = $("#token").val();
        var salt = $("#salt").val();

        $.ajax({
            type: "post",
            dataType: "json",
            url: "login",
            data: {
                'username': encodeURIComponent(encryptByDES($('#username').val()+salt, key)),
                'password': encodeURIComponent(encryptByDES($('#password').val()+salt, key)),
                'code':$('#code').val()
            },
            success: function (data) {
                logcomplete(data);
            },
            error: function () {
                alert("请求异常");
            }
        });
    }

    $(function () {
        $(".reloadverify").click(function () {
            changeverify();
        });
    })

    function changeverify() {
        var verifyimg = $(".verifyimg").attr("src");
        if (verifyimg.indexOf('?') > 0) {
            $(".verifyimg").attr("src", verifyimg + '&random=' + Math.random());
        } else {
            $(".verifyimg").attr("src", verifyimg.replace(/\?.*$/, '') + '?' + Math.random());
        }
    }

    function logcheckForm() {
        if ('' == $.trim($('#username').val())) {
            layer.msg('请输入登录用户名', {icon: 5, time: 2000}, function (index) {
                layer.close(index);
                $('#member_list_email').focus();
            });
            return false;
        }

        if ('' == $.trim($('#password').val())) {
            layer.msg('请输入登录密码', {icon: 5, time: 2000}, function (index) {
                layer.close(index);
                $('#member_list_email').focus();
            });
            return false;
        }

        if ('' == $.trim($('#code').val())) {
            layer.msg('请输入验证码', {icon: 5, time: 1000}, function (index) {
                layer.close(index);
                $('#code').focus();
            });
            return false;
        }
        return true;
    }

    function logcomplete(data) {
        if (data.status == 1) {
            layer.msg(data.info, {icon: 6, time: 1000}, function (index) {
                layer.close(index);
                window.location.href = "user";
            });
        } else {
            layer.msg(data.info, {icon: 5, time: 3000});
            $(".reloadverify").click();
            return false;
        }

    }

    function encryptByDES(message, key) {
        var keyHex = CryptoJS.enc.Utf8.parse(key);
        var encrypted = CryptoJS.DES.encrypt(message, keyHex, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
        return encrypted.toString();
    }
</script>
